package controllers;


import java.util.*;

import com.ani.mydragon.dto.menu.*;
import com.ani.mydragon.dto.template.*;

import dto.retjson.*;

import play.mvc.*;
import play.libs.*;
import services.frame.*;
import services.user.*;
import utils.MVCUtils;

public class FrontEndFrameController extends BaseController {
	
	//menu controllers
    public static Result bannerMenuObjs() {
    	List<MenuObjDto> menuObjects = AniFrameMenuService.allMenuObjects();
        return ok(Json.toJson(new RetDataDto(true, "ok", menuObjects)));
    }
    
    //dashboard controllers
    
    //app controllers
    public static Result userOwnedAppsList(){
        return pageRequestConstructor(
                AniAppFrameService.publicAppList(
                        MVCUtils.deleteUrlParams(
                                routes.AniAppController.queryUserOwnedApps(
                                        0L,
                                        0L,
                                        0L,
                                        0L,
                                        "",
                                        0
                                ).url()
                        ),
                        "MY_APPS",
                        "MY_APPS_PAGE"
                )
        );
    }
    public static Result installedAppsList(){
        return pageRequestConstructor(
                AniAppFrameService.publicAppList(
                        MVCUtils.deleteUrlParams(
                                routes.AniAppController.queryUserInstalledApps(
                                        0L,
                                        0L,
                                        "",
                                        1
                                ).url()
                        ),
                        "INSTALLED_APPS",
                        "INSTALLED_APPS_PAGE"
                )
        );
    }
    public static Result appDetailsPage(){
        return pageRequestConstructor(
                AniAppFrameService.appDetailPage()
        );
    }
    public static Result appRegister(){
    	return pageRequestConstructor(
                AniAppFrameService.appRegForm(
                        AniLocalUserService.currentLoginUser()
                )
        );
    }

    //api controllers
    public static Result apiRegister(Long appId){
        return pageRequestConstructor(
                AniApiFrameService.apiRegForm(
                        AniLocalUserService.currentLoginUser(),
                        appId
                )
        );
    }
    
    //user controllers

    //infrastructure
    private static Result pageRequestConstructor(PageTemplate onePage){
        try{
            return ok(
                    Json.toJson(
                            new RetDataDto(
                                    true,
                                    "ok",
                                    onePage
                            )
                    )
            );
        }catch (Exception e){
            return ok(Json.toJson(
                    new RetDataDto(false, e.getMessage())
            ));
        }
    }
    
}